package com.zwps.common.mybatis.plus.interceptor;

import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.schema.Table;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * 当前线程有效并且只进行一次的条件过滤
 * 
 * @ClassName: ThreadLocalOnceDataPermissionnterceptor
 * @Description:
 * @author lyh
 * @date 2023年9月21日 下午5:00:53
 *
 */
public class ThreadLocalOnceDataPermissionInterceptor extends ThreadLocalDataPermissionInterceptor {

    protected List<Function<Table, Expression>> checkTable(Map<String, List<Function<Table, Expression>>> fillTableMap,
            String tableName) {
        List<Function<Table, Expression>> fieldValueList = null;
        try {
            fieldValueList = super.checkTable(fillTableMap, tableName);
        } finally {
            if (fieldValueList != null && THREAD_LOCAL_TARGET_TABLE.get().remove(tableName) == null) {
                throw new RuntimeException("Remove table result is null, table name: " + tableName);
            }
        }
        return fieldValueList;
    }
}
